//
//  ZiXunCell.swift
//  BaseSwift
//
//  Created by gh on 2019/10/6.
//  Copyright © 2019 ghwang. All rights reserved.
//

import UIKit


class ZiXunCell: UITableViewCell {

    let containerView = UIView()
    let icon = UILabel()
    let nickLab = UILabel()
    let timeLab = UILabel()
    let contLab = UILabel()
    
    let icon1 = UILabel()
    let nickLab1 = UILabel()
    let timeLab1 = UILabel()
    let contLab1 = UILabel()
    
    let typeLab = UILabel()
    let nameLab = UILabel()
    let answerBg = UIView()
    let line = UIView()

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.contentView.addSubview(containerView)
        self.containerView.sd_cornerRadius = 8
        self.backgroundColor = UIColor.backgroundColor
        containerView.backgroundColor = UIColor.white
        self.selectionStyle = .none

        let _ = containerView.sd_layout()?.spaceToSuperView(UIEdgeInsets(top: 15, left: 12, bottom: 0, right: 12))
        
        containerView.sd_addSubviews([icon,nickLab,timeLab,contLab])
        
        icon.backgroundColor = UIColor.init(hexString: "#90939C")
        icon.text = "问"
        icon.textAlignment = .center
        icon.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.5))
        icon.textColor = UIColor.white
        let _ = icon.sd_layout()?.widthIs(24)!.heightIs(24)!.leftSpaceToView(containerView,16)!.topSpaceToView(containerView,16)
        icon.sd_cornerRadius = 4
        

        nickLab.textColor = UIColor.textTitleColorBlack
        nickLab.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.2))
        nickLab.text = "核桃酥"
        let _ = nickLab.sd_layout()?.leftSpaceToView(icon,16)!.heightIs(20)!.topSpaceToView(containerView,16)!.rightSpaceToView(containerView,45)
        
        timeLab.textColor = UIColor.textPlaceHolderColor
        timeLab.font = UIFont.smallerFont
        timeLab.text = "2019-09-09"
        let _ = timeLab.sd_layout()?.leftSpaceToView(icon,16)!.heightIs(15)!.topSpaceToView(nickLab,2)!.rightSpaceToView(containerView,45)
        
        contLab.textColor = UIColor.tabbarDefaultTextColor
        contLab.font = UIFont.commonFont
        contLab.text = "这里是我发表的评论，可以删除，照过可以通过左滑查看更多；评论内容超过三行的话，就折叠起来…"
        let _ = contLab.sd_layout()?.leftSpaceToView(icon,16)!.autoHeightRatio(0)!.topSpaceToView(timeLab,16)!.rightSpaceToView(containerView,16)
        contLab.setMaxNumberOfLinesToShow(2)
        
        containerView.addSubview(answerBg)
        let _ = answerBg.sd_layout()?.widthRatioToView(containerView,1)!.topSpaceToView(contLab,16)!.autoHeightRatio(0)
        
        answerBg.sd_addSubviews([icon1,nickLab1,timeLab1,contLab1])

        icon1.backgroundColor = UIColor.GP_Green_Color
        icon1.text = "答"
        icon1.textAlignment = .center
        icon1.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.5))
        icon1.textColor = UIColor.white
        let _ = icon1.sd_layout()?.widthIs(24)!.heightIs(24)!.leftSpaceToView(answerBg,16)!.topSpaceToView(answerBg,16)
        icon1.sd_cornerRadius = 4
        

        nickLab1.textColor = UIColor.textTitleColorBlack
        nickLab1.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.2))
        nickLab1.text = "核桃酥"
        let _ = nickLab1.sd_layout()?.leftSpaceToView(icon,16)!.heightIs(20)!.topSpaceToView(answerBg,16)!.rightSpaceToView(answerBg,45)
        
        timeLab1.textColor = UIColor.textPlaceHolderColor
        timeLab1.font = UIFont.smallerFont
        timeLab1.text = "2019-09-09"
        let _ = timeLab1.sd_layout()?.leftSpaceToView(icon,16)!.heightIs(15)!.topSpaceToView(nickLab1,2)!.rightSpaceToView(answerBg,45)
        
        contLab1.textColor = UIColor.tabbarDefaultTextColor
        contLab1.font = UIFont.commonFont
        contLab1.text = "这里是我发表的评论，可以删除，照过可以通过左滑查看更多；评论内容超过三行的话，就折叠起来…"
        let _ = contLab1.sd_layout()?.leftSpaceToView(icon,16)!.autoHeightRatio(0)!.topSpaceToView(timeLab1,16)!.rightSpaceToView(answerBg,16)
        contLab1.setMaxNumberOfLinesToShow(2)
        answerBg.setupAutoHeight(withBottomView: contLab1, bottomMargin: 0)
        
        
        
        

        
        let bottomView = UIView()
        containerView.addSubview(bottomView)
        let _ = bottomView.sd_layout()?.widthRatioToView(containerView,1)!.bottomSpaceToView(containerView,0)!.heightIs(55)
        bottomView.addSubview(typeLab)
        typeLab.textColor = UIColor.GP_Orange_Color
        typeLab.textAlignment = .center
        typeLab.text = "产品"
        typeLab.font = UIFont.smallerLessthanFont
        let _ = typeLab.sd_layout()?.leftSpaceToView(bottomView,16)!.centerYEqualToView(bottomView)!.widthIs(35)!.heightIs(16)
        typeLab.sd_cornerRadius = 2
        typeLab.layer.borderColor = UIColor.GP_Orange_Color.cgColor
        typeLab.layer.borderWidth = 1
        
        let line = UIView()
        line.backgroundColor = UIColor.lineColor
        bottomView.addSubview(line)
        let _ = line.sd_layout()?.widthRatioToView(bottomView,1)!.heightIs(1)!.topSpaceToView(bottomView,0)
        
        nameLab.font = UIFont.commonFont
        nameLab.textColor = UIColor.textTitleColorBlack
        nameLab.text = "阿根廷、南极午夜阳号18天之旅"
        bottomView.addSubview(nameLab)
        let _ = nameLab.sd_layout()?.leftSpaceToView(typeLab,16)!.heightIs(20)!.centerYEqualToView(bottomView)!.rightSpaceToView(bottomView,35)
        
        let rigIcon = UIImageView()
        rigIcon.image = UIImage(named: "向右")
        bottomView.addSubview(rigIcon)
        let _ = rigIcon.sd_layout()?.widthIs(16)!.heightIs(16)!.centerYEqualToView(bottomView)!.rightSpaceToView(bottomView,16)
        
        
        
        
    }
    
    func setModel(mod:ZiXunVo) {
        
        contLab.updateLayout()

        answerBg.removeFromSuperview()
        nickLab.text = mod.userName
        timeLab.text = mod.createTime?.split(string: "T").first
        nameLab.text = mod.pdtName
        contLab.text = mod.content
        
        
        if mod.reContent != nil {
            
            containerView.addSubview(answerBg)
            let _ = answerBg.sd_layout()?.widthRatioToView(containerView,1)!.topSpaceToView(contLab,16)!.autoHeightRatio(0)
            
            answerBg.sd_addSubviews([icon1,nickLab1,timeLab1,contLab1])

            icon1.backgroundColor = UIColor.GP_Green_Color
            icon1.text = "答"
            icon1.textAlignment = .center
            icon1.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.5))
            icon1.textColor = UIColor.white
            let _ = icon1.sd_layout()?.widthIs(24)!.heightIs(24)!.leftSpaceToView(answerBg,16)!.topSpaceToView(answerBg,16)
            icon1.sd_cornerRadius = 4
            

            nickLab1.textColor = UIColor.textTitleColorBlack
            nickLab1.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.2))
            nickLab1.text = mod.reName
            let _ = nickLab1.sd_layout()?.leftSpaceToView(icon,16)!.heightIs(20)!.topSpaceToView(answerBg,16)!.rightSpaceToView(answerBg,45)
            
            timeLab1.textColor = UIColor.textPlaceHolderColor
            timeLab1.font = UIFont.smallerFont
            timeLab1.text = mod.reTime?.split(string: "T").first
            let _ = timeLab1.sd_layout()?.leftSpaceToView(icon,16)!.heightIs(15)!.topSpaceToView(nickLab1,2)!.rightSpaceToView(answerBg,45)
            
            contLab1.textColor = UIColor.tabbarDefaultTextColor
            contLab1.font = UIFont.commonFont
            contLab1.text = mod.reContent
            let _ = contLab1.sd_layout()?.leftSpaceToView(icon,16)!.autoHeightRatio(0)!.topSpaceToView(timeLab1,16)!.rightSpaceToView(answerBg,16)
            contLab1.setMaxNumberOfLinesToShow(2)
            answerBg.setupAutoHeight(withBottomView: contLab1, bottomMargin: 0)
            

            
            
        }
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
